package com.guslegend.service.impl;

import com.guslegend.manager.ProductManager;
import com.guslegend.model.ProductDO;
import com.guslegend.service.ProductService;
import com.guslegend.vo.ProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductManager productManager;

    @Override
    public List<ProductVO> list() {

        List<ProductDO> list=productManager.list();
        List<ProductVO> collect=list.stream().map(obj-> beanProcess(obj)).collect(Collectors.toList());
        return collect;
    }

    @Override
    public ProductVO findDetailById(long productId) {

        ProductDO productDO= productManager.findDetailById(productId);

        return beanProcess(productDO);
    }

    private ProductVO beanProcess(ProductDO productDO){

        ProductVO productVO=new ProductVO();
        BeanUtils.copyProperties(productDO,productVO);
        return productVO;
    }
}
